package com.zhengdongzulin.zuke.app.main.mine.contract

import android.content.Intent
import com.lxj.androidktx.core.*
import com.zhengdongzulin.zuke.R
import com.zhengdongzulin.zuke.app.main.ZKWebviewActivity
import com.zhengdongzulin.zuke.base.*
import com.zhengdongzulin.zuke.databinding.ZkActivityContractDetailsBinding
import com.zhengdongzulin.zuke.ext.put
import com.zhengdongzulin.zuke.ext.start


/**
 * jeff
 * 我的合同
 * 2021-03-27 17:50:47
 */
class ZKContractDetailsActivity :
    BaseActivity<ContractDetailsVm, ZkActivityContractDetailsBinding>() {

    override fun getLayoutResId(): Int = R.layout.zk_activity_contract_details

    override fun initVM(): ContractDetailsVm = getVM(ContractDetailsVm::class.java)

    override fun initView() {
        setTitleContent("合同详情")
        setRightButton("电子合同") {
        }
        mView.statusView.showLoading()
        mViewModel.contract_detail(intent.getStringExtra("id")!!)
    }

    override fun initData() {


    }

    override fun initListener() {
    }

    override fun startObserve() {
        mViewModel.contract_detail.observe(this, androidx.lifecycle.Observer {

            mView.run {

                tvHouseName.text = "${it.houseName}${it.houseNumber}"
                tvAddress.text = "${it.houseAddress}"
                tvDoorName.text = "${it.doorName}"
                tvArea.text = "${it.area}平"
                tvRenterName.text = "${it.renterName}"
                tvRenterPhone.text = "${it.renterPhone}"
                tvContractId.text = "${it.contractNo}"
                tvTime.text = "${it.startDate} 至 ${it.endDate}"
                tvStatusName.text = "${it.statusName}"
                tvRentPrice.text = "${it.rentPrice}元/月"
                tvDepositPrice.text = "${it.depositPrice}元/月"
                tvPaymentMethod.text = "${it.paymentMethod}"
                statusView.showContent()
            }

            if (!it.contractAddress.isNullOrEmpty()) {
                setRightButton("电子合同") {
                    Intent().put("url", it.contractAddress)
                        .start(this@ZKContractDetailsActivity, ZKWebviewActivity::class.java)
                }
            }
        })
        mViewModel.contract_detail.state.observe(this, getObserver(mViewModel.contract_detail))
    }

}